<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var time = prompt("请输入日期：例：01月01日20xx年");
        // var time = "01月03日2020年";
        var monthNum = time.indexOf("月", time);
        var dayNum = time.indexOf("日", time);
        var yearNum = time.indexOf("年", time);
        if (monthNum != -1 || dayNum != -1 || yearNum != -1) {
            var month = time.substring(0, monthNum);
            var day = time.substring(monthNum + 1, dayNum);
            var year = time.substring(dayNum + 1, time.length - 1);

            document.write("转换为：" + year + "年" + month + "月" + day + "日");
        } else {
            document.write("请输入正确格式的日期");
        }
    </script>
</body>

</html>